package com.gxuwz.weatherapp;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    
    private ViewPager2 viewPager;
    private WeatherPagerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewPager = findViewById(R.id.viewPager);
        adapter = new WeatherPagerAdapter();
        
        // 设置适配器
        viewPager.setAdapter(adapter);
        
        // 设置页面切换动画
        viewPager.setPageTransformer(new WeatherPageTransformer());
        
        // 设置页面间距，使切换效果更明显
        viewPager.setOffscreenPageLimit(1);
        
        // 模拟数据
        List<WeatherPagerAdapter.WeatherData> weatherDataList = new ArrayList<>();
        
        // 万秀区天气数据
        List<HourlyForecastAdapter.HourlyForecast> wanxiuHourly = Arrays.asList(
            new HourlyForecastAdapter.HourlyForecast("现在", android.R.drawable.ic_menu_gallery, "31°"),
            new HourlyForecastAdapter.HourlyForecast("18:00", android.R.drawable.ic_menu_gallery, "32°"),
            new HourlyForecastAdapter.HourlyForecast("19:00", android.R.drawable.ic_menu_gallery, "32°"),
            new HourlyForecastAdapter.HourlyForecast("19:17", android.R.drawable.ic_menu_gallery, "32°"),
            new HourlyForecastAdapter.HourlyForecast("20:00", android.R.drawable.ic_menu_gallery, "32°"),
            new HourlyForecastAdapter.HourlyForecast("21:00", android.R.drawable.ic_menu_gallery, "32°")
        );
        
        List<WeatherPagerAdapter.DailyForecast> wanxiuDaily = Arrays.asList(
            new WeatherPagerAdapter.DailyForecast("5月31日", "昨天", 
                android.R.drawable.ic_menu_gallery, "24° / 31°", null),
            new WeatherPagerAdapter.DailyForecast("6月1日", "今天", 
                android.R.drawable.ic_menu_gallery, "25° / 34°", "60%"),
            new WeatherPagerAdapter.DailyForecast("6月2日", "明天", 
                android.R.drawable.ic_menu_gallery, "23° / 32°", "60%"),
            new WeatherPagerAdapter.DailyForecast("6月3日", "周二", 
                android.R.drawable.ic_menu_gallery, "23° / 31°", "60%"),
            new WeatherPagerAdapter.DailyForecast("6月4日", "周三", 
                android.R.drawable.ic_menu_gallery, "25° / 33°", null)
        );
        
        weatherDataList.add(new WeatherPagerAdapter.WeatherData(
            "万秀区",
            "31°",
            "阴 25°/34° 空气优 32",
            "暴雨蓝色预警",
            "广西气象台2025年06月01日17时30分发布暴雨四级（蓝色）预警，预计：未来24小时，柳州、河池、桂林三市及百色...",
            wanxiuHourly,
            wanxiuDaily
        ));

        // 南宁市天气数据
        List<HourlyForecastAdapter.HourlyForecast> nanningHourly = Arrays.asList(
            new HourlyForecastAdapter.HourlyForecast("现在", android.R.drawable.ic_menu_gallery, "33°"),
            new HourlyForecastAdapter.HourlyForecast("19:00", android.R.drawable.ic_menu_gallery, "31°"),
            new HourlyForecastAdapter.HourlyForecast("19:28", android.R.drawable.ic_menu_gallery, "31°"),
            new HourlyForecastAdapter.HourlyForecast("20:00", android.R.drawable.ic_menu_gallery, "30°"),
            new HourlyForecastAdapter.HourlyForecast("21:00", android.R.drawable.ic_menu_gallery, "29°"),
            new HourlyForecastAdapter.HourlyForecast("22:00", android.R.drawable.ic_menu_gallery, "28°")
        );
        
        List<WeatherPagerAdapter.DailyForecast> nanningDaily = Arrays.asList(
            new WeatherPagerAdapter.DailyForecast("5月31日", "昨天", 
                android.R.drawable.ic_menu_gallery, "25° / 32°", null),
            new WeatherPagerAdapter.DailyForecast("6月1日", "今天", 
                android.R.drawable.ic_menu_gallery, "26° / 35°", null),
            new WeatherPagerAdapter.DailyForecast("6月2日", "明天", 
                android.R.drawable.ic_menu_gallery, "24° / 34°", "60%"),
            new WeatherPagerAdapter.DailyForecast("6月3日", "周二", 
                android.R.drawable.ic_menu_gallery, "24° / 32°", null),
            new WeatherPagerAdapter.DailyForecast("6月4日", "周三", 
                android.R.drawable.ic_menu_gallery, "24° / 33°", null)
        );
        
        weatherDataList.add(new WeatherPagerAdapter.WeatherData(
            "南宁",
            "33°",
            "阴 26°/35° 空气优 43",
            "暴雨蓝色预警",
            "广西气象台2025年06月01日17时30分发布暴雨四级（蓝色）预警，预计：未来24小时，柳州、河池、桂林三市及百色...",
            nanningHourly,
            nanningDaily
        ));
        
        // 更新数据
        adapter.updateData(weatherDataList);

        // 设置当前显示的城市为南宁（第二个城市）
        viewPager.setCurrentItem(1, false);
    }
} 